package com.yuefresh.dish;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.yuefresh.util.RequestUtil;


/**
 * 
 * @Description: JSON数据接口
 * @author junhao
 * @since 2013-3-17 下午15:29:25 
 */
@Controller
@RequestMapping("/json")
public class JsonController {
	private final static Logger logger = LoggerFactory.getLogger(JsonController.class);
	
	/**
	 * 根据集团获取餐厅
	 * @id company id
	 */
	@RequestMapping(params="m=get_restaurants")
	public ModelAndView getRestaurants(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "酒店集团，获取餐厅信息");
		StringBuffer jsonsb = new StringBuffer();
		
		jsonsb.append("{\"restaurants\":[{\"id\":\"1\",\"name\":\"颐丰阁中餐厅\",\"city\":\"昆山\",\"region\":\"城西\",\"city\":\"马鞍山路1888号\",\"account_psw\":\"123\"},");
		jsonsb.append("{\"id\":\"2\",\"name\":\"清澄西餐厅\",\"city\":\"昆山\",\"region\":\"城西\",\"city\":\"马鞍山路1888号\",\"account_psw\":\"123\"}]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 根据餐厅获取访问用户（服务员）
	 * @id restautant id
	 */
	@RequestMapping(params="m=get_users")
	public ModelAndView getUsers(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "餐厅，获取服务员信息");
		StringBuffer jsonsb = new StringBuffer();
		
		jsonsb.append("{\"users\":[{\"user_id\":\"C0605001\",\"name\":\"杨怡\",\"password\":\"1238\",\"roles\":[{\"role_id\":\"W\",\"name\":\"服务员\"}]},");
		jsonsb.append("{\"user_id\":\"C0605002\",\"name\":\"徐蓉\",\"password\":\"1234\",\"roles\":[{\"role_id\":\"W\",\"name\":\"服务员\"},{\"role_id\":\"A\",\"name\":\"管理员\"}]}]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 根据餐厅id获取所有桌号，包间信息
	 * @id restautant id
	 */
	@RequestMapping(params="m=get_areas")
	public ModelAndView getAreas(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "餐厅，获取区域信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"restautant\":{\"id\":\"1\",\"name\":\"颐丰阁\",\"comapny\":{\"company_ID\":\"1000\",\"name\":\"***酒店\"}},\"area\":[");
		jsonsb.append("{\"id\":\"2\",\"code\":\"001\",\"name\":\"一楼\",\"description\":\"\",\"type\":\"FLOO\",\"capacity\":\"\",\"display_child\":\"0\",\"img_url\":\"\",\"children\":[");
		jsonsb.append("{\"id\":\"4\",\"code\":\"011\",\"name\":\"大厅\",\"description\":\"一楼大厅\",\"type\":\"HALL\",\"capacity\":\"\",\"display_child\":\"0\",\"img_url\":\"default.jpg\",\"children\":[");
		jsonsb.append("{\"id\":\"5\",\"code\":\"108\",\"name\":\"一号\",\"description\":\"\",\"type\":\"TABL\",\"capacity\":\"10\",\"display_child\":\"0\",\"img_url\":\"01.jpg\"},");
		jsonsb.append("{\"id\":\"6\",\"code\":\"109\",\"name\":\"二号\",\"description\":\"\",\"type\":\"TABL\",\"capacity\":\"12\",\"display_child\":\"0\",\"img_url\":\"01.jpg\"}");
		jsonsb.append("]},");
		jsonsb.append("{\"id\":\"4\",\"code\":\"111\",\"name\":\"放鹤厅\",\"description\":\"\",\"type\":\"ROOM\",\"capacity\":\"10\",\"display_child\":\"0\",\"img_url\":\"default.jpg\"}");
		jsonsb.append("]},");
		jsonsb.append("{\"id\":\"3\",\"code\":\"002\",\"name\":\"二楼\",\"description\":\"\",\"type\":\"FLOO\",\"capacity\":\"\",\"display_child\":\"0\",\"img_url\":\"\",\"children\":[");
		jsonsb.append("{\"id\":\"14\",\"code\":\"204\",\"name\":\"玲珑厅\",\"description\":\"\",\"type\":\"ROOM\",\"capacity\":\"18\",\"display_child\":\"0\",\"img_url\":\"01.jpg\"},");
		jsonsb.append("{\"id\":\"19\",\"code\":\"206\",\"name\":\"种玉厅\",\"description\":\"\",\"type\":\"ROOM\",\"capacity\":\"14\",\"display_child\":\"0\",\"img_url\":\"01.jpg\"}");
		jsonsb.append("]}");
		jsonsb.append("]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 根据餐厅id获取菜单
	 * @id restautant id
	 */
	@RequestMapping(params="m=get_menus")
	public ModelAndView getMenus(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "餐厅，获取菜单信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"menus\":[{\"id\":\"1\",\"name\":\"标准\"},{\"id\":\"2\",\"name\":\"九月阳澄湖\"}]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 根据菜单获取菜品种类
	 * @id menu id
	 */
	@RequestMapping(params="m=get_dish_types")
	public ModelAndView getDishTypes(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "菜单，获取菜品分类信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"dish_types\":[{\"id\":\"1\",\"name\":\"家常菜\",\"img_path\":\"a2.jpg\"},");
		jsonsb.append("{\"id\":\"2\",\"name\":\"海鲜\",\"img_path\":\"a3.jpg\"},");
		jsonsb.append("{\"id\":\"3\",\"name\":\"凉菜\",\"img_path\":\"a3.jpg\"},");
		jsonsb.append("{\"id\":\"4\",\"name\":\"创意菜\",\"img_path\":\"a3.jpg\"},");
		jsonsb.append("{\"id\":\"5\",\"name\":\"甜品\",\"img_path\":\"a3.jpg\"},");
		jsonsb.append("{\"id\":\"6\",\"name\":\"酒水饮料\",\"img_path\":\"a3.jpg\"},");
		jsonsb.append("{\"id\":\"7\",\"name\":\"煲汤\",\"img_path\":\"a3.jpg\"}]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 根据菜单获取菜品
	 * @id menu id
	 */
	@RequestMapping(params="m=get_dishes")
	public ModelAndView getDishes(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "菜单，获取菜品信息");
		String tid = RequestUtil.getString(request, "tid");
		logger.info("tid:" + tid);
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"dishes\":[{\"id\":\"1\",\"name\":\"西红柿炒鸡蛋\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"1\",\"name\":\"家常菜\"},\"price\":\"22.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a1.jpg\",\"img_size\":\"220*146\",\"related_dishes\":[{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"price\":\"21.00\",\"img_path\":\"a8.jpg\",\"img_size\":\"220*330\"}]},");
		jsonsb.append("{\"id\":\"2\",\"name\":\"蜂蜜厚多士\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"创意菜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a2.jpg\",\"img_size\":\"220*146\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"3\",\"name\":\"石锅拌饭\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"家常菜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"0\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a3.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"4\",\"name\":\"杏仁木瓜银耳炖\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"煲汤\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"0\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a4.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"5\",\"name\":\"阳澄湖大闸蟹\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"},{\"id\":\"2\",\"name\":\"九月阳澄湖\"}],\"type\":{\"id\":\"3\",\"name\":\"海鲜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"0\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a5.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"6\",\"name\":\"紫菜包饭\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"创意菜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"0\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a6.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"7\",\"name\":\"蜜豆圆子抹茶冰激凌\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"甜品\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a7.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"description\":\"很好\",\"type\":{\"id\":\"3\",\"name\":\"凉菜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a8.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]}]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	/**
	 * 根据菜单获取推荐特色菜品
	 * @id menu id
	 */
	@RequestMapping(params="m=get_special_dishes")
	public ModelAndView getSpecialDishes(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "菜单，获取菜品信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"dishes\":[{\"id\":\"1\",\"name\":\"西红柿炒鸡蛋\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"1\",\"name\":\"家常菜\"},\"price\":\"22.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a1.jpg\",\"img_size\":\"220*146\",\"related_dishes\":[{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"price\":\"21.00\",\"img_path\":\"a8.jpg\"}]},");
		jsonsb.append("{\"id\":\"2\",\"name\":\"蜂蜜厚多士\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"创意菜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a2.jpg\",\"img_size\":\"220*146\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"7\",\"name\":\"蜜豆圆子抹茶冰激凌\",\"description\":\"很好\",\"menus\":[{\"id\":\"1\",\"name\":\"标准\"}],\"type\":{\"id\":\"3\",\"name\":\"甜品\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a7.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]},");
		jsonsb.append("{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"description\":\"很好\",\"type\":{\"id\":\"3\",\"name\":\"凉菜\"},\"price\":\"20.00\",\"price_unit\":\"份\",\"delicious_grade\":\"5\",\"pungent_grade\":\"1\",\"is_special\":\"1\",\"sales_qty\":\"20\",\"recipe_summary\":\"\",\"chef_word\":\"\",\"img_path\":\"a8.jpg\",\"img_size\":\"220*330\",\"related_dishes\":[]}]}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 获取用餐信息
	 * @id area id
	 */
	@RequestMapping(params="m=get_meal")
	public ModelAndView getMeal(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "区域，获取用餐信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"id\":\"1\",\"code\":\"100-131022-0043\",\"status\":\"INPR\",\"area\":{\"id\":\"19\",\"code\":\"206\",\"name\":\"种玉厅\"},\"number\":\"5\",\"waiter\":{\"user_id\":\"C0605001\",\"name\":\"杨怡\",\"password\":\"1238\"},\"customer\":\"金先生-18913216788\"}");

		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 获取用餐的未接收（执行中）订单信息
	 * @id meal id
	 */
	@RequestMapping(params="m=get_inpr_order")
	public ModelAndView getInprOrder(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "用餐信息，获取未接收订单信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"id\":\"102\",\"code\":\"100-131022-0043-03\",\"quantity\":\"3\",\"amount\":\"65.00\",\"meal\":{\"id\":\"1\",\"code\":\"100-131022-0043\",\"status\":\"INPR\"},\"status\":\"INPR\",\"order_date\":\"2013-10-29 10:12\",\"order_item\":[{\"id\":\"122\",\"dish\":{\"id\":\"1\",\"name\":\"西红柿炒鸡蛋\",\"price\":\"22.00\",\"discount\":\"1\",\"img_url\":\"a1.jpg\"},\"quantity\":\"2\",\"amount\":\"44\"},{\"id\":\"123\",\"dish\":{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"price\":\"21.00\",\"discount\":\"1\",\"img_url\":\"a21.jpg\"},\"quantity\":\"1\",\"amount\":\"21\"}]}");

		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 获取用餐的已接收订单信息
	 * @id meal id
	 */
	@RequestMapping(params="m=get_acpt_orders")
	public ModelAndView getAcptOrders(HttpServletRequest request, Long id) {
		logger.info("根据" + id + "用餐信息，获取已接收订单信息");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"acpt_orders\":[{\"id\":\"101\",\"code\":\"100-131022-0043-02\",\"meal\":{\"id\":\"1\",\"code\":\"100-131022-0043\",\"status\":\"INPR\"},\"status\":\"ACPT\",\"order_date\":\"2013-10-29 10:01\",\"order_item\":[{\"id\":\"102\",\"dish\":{\"id\":\"1\",\"name\":\"西红柿炒鸡蛋\",\"price\":\"22.00\",\"discount\":\"1\",\"img_url\":\"a1.jpg\"},\"quantity\":\"1\",\"amount\":\"22\"},{\"id\":\"103\",\"dish\":{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"price\":\"21.00\",\"discount\":\"1\",\"img_url\":\"a21.jpg\"},\"quantity\":\"1\",\"amount\":\"21\"}]},");
		jsonsb.append("{\"id\":\"100\",\"code\":\"100-131022-0043-01\",\"meal\":{\"id\":\"1\",\"code\":\"100-131022-0043\",\"status\":\"INPR\"},\"status\":\"ACPT\",\"order_date\":\"2013-10-29 09:30\",\"order_item\":[{\"id\":\"97\",\"dish\":{\"id\":\"1\",\"name\":\"西红柿炒鸡蛋\",\"price\":\"22.00\",\"discount\":\"1\",\"img_url\":\"a1.jpg\"},\"quantity\":\"1\",\"amount\":\"22\"},{\"id\":\"98\",\"dish\":{\"id\":\"21\",\"name\":\"桂花糯米糖藕\",\"price\":\"21.00\",\"discount\":\"1\",\"img_url\":\"a21.jpg\"},\"quantity\":\"2\",\"amount\":\"42\"}]}],\"quantity\":\"5\",\"amount\":\"107.00\"}");

		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 为本次用餐选菜
	 * @id meal id
	 * @did dish id
	 */
	@RequestMapping(params="m=choose_dish")
	public ModelAndView chooseDish(HttpServletRequest request, Long id, Long did) {
		logger.info("为" + id + "用餐，选取" + did + "菜品");
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"success\":\"0\",\"info\":\"成功\"}");

		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 为本次用餐所选菜+1或-1
	 * @id meal id
	 * @did dish id
	 */
	@RequestMapping(params="m=change_dish")
	public ModelAndView changeDish(HttpServletRequest request, Long id, Long did, Integer quantity) {
		logger.info("为" + id + "用餐，更改" + did + "菜品的数量到" + quantity);
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"success\":\"0\",\"info\":\"成功\"}");

		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	
	/**
	 * 接收用餐的订单信息
	 * @id order id
	 */
	@RequestMapping(params="m=accept_order")
	public ModelAndView acceptOrder(HttpServletRequest request, Long id) {
		logger.info("接收订单" + id);
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"success\":\"0\",\"info\":\"成功\"}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
	
	/**
	 * 结算用餐信息
	 * @id meal id
	 */
	@RequestMapping(params="m=settle_meal")
	public ModelAndView settleMeal(HttpServletRequest request, Long id) {
		logger.info("结算用餐" + id);
		StringBuffer jsonsb = new StringBuffer();
		jsonsb.append("{\"success\":\"0\",\"info\":\"成功\"}");
		//Forward===================================================
		ModelAndView mv = new ModelAndView("common/ajax");
		mv.addObject("outString", jsonsb.toString());
		
		return mv;
	}
}
